package com.java.juc;

import java.util.Objects;
import java.util.concurrent.CountDownLatch;

/**
 * @author wangning
 * @date 2023/5/15 16:47
 * 倒计时：
 * 当班里有人的时候，班长不允许锁门，只有所有人走完，班长才能走人
 */
public class CountDownLatchDemo {

    public static void main(String[] args) throws Exception {
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "\t 国，被灭");
                countDownLatch.countDown();

            }, Objects.requireNonNull(CountryEnum.foreach_CountryEnum(i)).getName()).start();

        }
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName() + "\t 秦国，一统天下");

        System.out.println();
        System.out.println();
        System.out.println(CountryEnum.ONE);
        System.out.println(CountryEnum.ONE.getKey());
        System.out.println(CountryEnum.ONE.getName());
    }

    private static void closeDoor() throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 0; i < 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "\t 上完自习，离开教室");
                countDownLatch.countDown();

            }, String.valueOf(i)).start();

        }
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName() + "\t 班长最后关门走人");
    }
}





